﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace server.filters
{
    public class InvocationChain
    {

        List<NetFilter>   filters ;

        int currentIndex;

        public InvocationChain(List<NetFilter> filters) { 
        
            this.filters = filters;
        }

        public InvocationChain(NetFilter filter)
        {

            this.filters = new List<NetFilter>() { filter };
        }

        public InvocationChain(InvocationChain chain)
        {

            this.filters = chain.filters;
            this.currentIndex = chain.currentIndex;
        }

        public void invoke(Object buffer)
        {

            if (currentIndex == filters.Count) {
                
                return ;
            }

            NetFilter filter = filters[currentIndex];

            currentIndex++;

            filter.invoke(buffer,this);

           
        }
    }
}
